
#include"game.h"

void menu() {
	printf("*********************\n");
	printf("*****   1.play    ***\n");
	printf("*****   0.exit    ***\n");
	printf("*********************\n");
}
void game() {
	char arr[row][row] = { 0 };
	//初始化棋盘
	init_board(arr, row);
	//打印棋盘
	print_board(arr, row);
	//下棋
	int r = 1;
	int count = 0;
	while (r && (count != 9)) {
		//玩家下棋
		player_chess(arr, row);
		print_board(arr, row);
		//判断是否游戏结束
		r = judge_end(arr, row);
		if (r == 0) {
			break;
		}
		count++;
		if (count == 9) {
			printf("平局！游戏结束！");
		}
		//电脑下棋
		com_chess(arr, row);
		print_board(arr, row);
		//判断是否游戏结束
		r = judge_end(arr, row);
		if (r == 0) {
			break;
		}
		count++;
	}
}
void test() {
	int n = 0;
	int temp = 1;
	do {
		//打印菜单
		menu();
		//判断是否进行游戏
		printf("请输入游戏是否进行:\n");
		scanf("%d", &n);
		switch (n) {
			case 1:
				printf("开始三子棋游戏\n");
				game();
				temp = 0;
				break;
			case 0:
				printf("退出三子棋游戏\n");
				temp = 0;
				break;
			default:
				printf("输入错误，重新输入\n");
				break;
		}
	} while (temp);
}
int main() {
	test();
	return 0;
}
